﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using Lswweb.Domain;
using Lswweb.Model;
using Lswweb.Common;

namespace Lswweb.Domain
{
    public static class PaymentFactory
    {
        public static IPaymentIPN GetPaymentIPN(HttpContext context)
        {
            return new Payment.Paypal.PaypalIPN(context,false);
        }

        public static IPayment GetPayment(OrderInfo order)
        {
            return new Payment.Paypal.Paypal(
                SiteSettings.Settings.PaymentPaypalUserName,
                order.Id.ToString(),
                order.TotalPrices.ToString(),
                false);
        }

        public static void Log(HttpContext context)
        {
            IList<string> list = new List<string>();

            list.Add("Url：" + context.Request.Url.PathAndQuery);

            foreach (string key in context.Request.Form.Keys)
            {
                list.Add(key + "=" + context.Request.Form[key]);
            }

            Log(context, list.ToArray());

        }
        public static void Log(HttpContext context,params string[] strs)
        {
            string path = context.Server.MapPath(string.Format("~/Log/{0}.txt", DateTime.Now.ToString().Replace(":", "")));
            using (StreamWriter fs = new StreamWriter(path, false, System.Text.Encoding.Default))
            {
                foreach (string item in strs)
                {
                    fs.WriteLine(item);
                }
            }
        }
    }
}
